import { _decorator, Component, director, instantiate, Node, Prefab, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('enemyManage')
export class enemyManage extends Component {

    @property(Prefab)
    enemyPrefab: Prefab | null = null;
    start() {
        // 没间隔2秒创建敌机
        this.schedule(()=>{
            //创建敌机
            this.createEnemy()
        },2)
    }
    createEnemy(){
        //实例化敌机
        let enemy = instantiate(this.enemyPrefab)
        //添加到场景中
        // 获取当前场景
let currentScene = director.getScene();
 
// 从当前场景中获取特定的节点
enemy.setPosition(new Vec3(
    Math.random()*300-150,
    this.node.position.y,
    0
))
enemy.setParent(this.node.getParent())
      
    }
    update(deltaTime: number) {
        
    }
}


